package com.viphuli.app.tool.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import butterknife.Bind;
import butterknife.OnClick;

import com.offroader.core.OffRoaderApp;
import com.offroader.utils.PhoneUtils;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.common.Constants.UserType;

public class AccountTypeAddDialogFragment extends BaseProgressDialogFragment {

	@Bind(R.id.id_account_type_nurse_btn)
	protected View nurseBtn;

	@Bind(R.id.id_account_type_nurse_arrange_btn)
	protected View nurseArrangeBtn;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		//无标题
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_account_type_dialog;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {
		
	}

	@Override
	protected void initData() {

	}

	@Override
	public void onStart() {
		super.onStart();

		initDialogLayout();
	}

	private void initDialogLayout() {
		//得到当前对话框对象（google不推荐直接创建dialog）
		Dialog dialog = getDialog();

		//得到对话框的窗体
		Window dialogWindow = dialog.getWindow();

		//设置窗体宽度全屏
		dialogWindow.setBackgroundDrawableResource(R.color.cl_common_page);
		int[] pixs = PhoneUtils.getScreenPix(OffRoaderApp.getInstance());
		WindowManager.LayoutParams layoutParams = dialogWindow.getAttributes();
		layoutParams.width = pixs[0];

		//设置窗体底部弹出
		layoutParams.gravity = Gravity.BOTTOM;

		//设置窗体弹出动画
		dialogWindow.setWindowAnimations(R.style.dialogWindowAnim);

		//设置窗体属性
		dialogWindow.setAttributes(layoutParams);
	}

	@OnClick({ R.id.id_account_type_nurse_layout, R.id.id_account_type_nurse_arrange_layout })
	public void selectNurse(View v) {
		
		AccountAddUserTypeFragment addUserTypeFrag = (AccountAddUserTypeFragment)getParentFragment();

		switch (v.getId()) {
		case R.id.id_account_type_nurse_layout:

			nurseBtn.setBackgroundResource(R.drawable.ic_arrange_type_selected);
			nurseArrangeBtn.setBackgroundResource(R.drawable.ic_arrange_type_un_selected);
			
			addUserTypeFrag.setSelectUserType(UserType.normal);
			
			break;

		case R.id.id_account_type_nurse_arrange_layout:

			nurseBtn.setBackgroundResource(R.drawable.ic_arrange_type_un_selected);
			nurseArrangeBtn.setBackgroundResource(R.drawable.ic_arrange_type_selected);

			addUserTypeFrag.setSelectUserType(UserType.arrange_admin);

			break;

		default:
			break;
		}
	}

	@OnClick(R.id.id_account_submit_btn)
	public void changeUserType(View v) {
		getDialog().dismiss();
		AccountAddUserTypeFragment addUserTypeFrag = (AccountAddUserTypeFragment)getParentFragment();
		UserType userType = addUserTypeFrag.getSelectUserType();
		addUserTypeFrag.getUserTypeText().setText(userType.getName());
	}
}
